import Mock from "mockjs";
var { newsList } = Mock.mock({
    "newsList|75": [{
        id: "@increment()",
        title: "@ctitle",
        contnet: "@cparagraph(5,10)",
        date: "@date(yyyy-MM-dd)",
        img_url: "@image('100x100','#eee','#fff','png','mockjs')"
    }]
});
const getQuery = (url, name) => {
    // console.log(url, name); 查找问好的位置
    const index = url.indexOf("?");
    // 当有找到？的时候 就截取截止
    if (index !== -1) {
        const queryStrArr = url.substr(index + 1).split("&");
        for (var i = 0; i < queryStrArr.length; i++) {
            const itemArr = queryStrArr[i].split("=");
            // console.log(query);
            if (itemArr[0] === name) {
                return itemArr[1];
            }
        }
    }
    return null;
    // asdf
};
// options是拿到axios的拼接的prams
Mock.mock(/\/api\/get\/res/, "get", options => {
    const pageindex = getQuery(options.url, "pageindex");
    const pagesize = getQuery(options.url, "pagesize");
    const totalPage = Math.ceil(newsList.length / pagesize);
    const start = (pageindex - 1) * pagesize;
    const end = pageindex * pagesize;
    // 1 0 - 9
    // 2 10 - 19
    // 3 20-29
    const list = pageindex > totalPage ? [] : newsList.slice(start, end);
    // console.log(list);
    return {
        status: 200,
        msg: "数据获取成功",
        list: list,
        total: totalPage
    };
});